package com.autumn.sms.service.mq;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.autumn.mq.event.EventHandlerConfigure;
import com.autumn.mq.event.EventMessage;
import com.autumn.mq.event.IEventHandler;
import com.autumn.sms.SmsEventData;
import com.autumn.sms.service.core.ISmsDispatchService;

/**
 * 短信事件处理器
 * 
 * @author 老码农
 *
 *         2018-01-12 09:13:58
 */
@Component
@EventHandlerConfigure(name = SmsEventData.EVENT_NAME, concurrentConsumers = 5)
public class SmsEventHandler implements IEventHandler<SmsEventData> {

	private final static Log logger = LogFactory.getLog(SmsEventHandler.class);

	@Autowired
	private ISmsDispatchService service;

	@Override
	public boolean errorAutoRepeatSend() {
		return true;
	}

	@Override
	public Log getLogger() {
		return logger;
	}

	@Override
	public void onHandler(EventMessage<SmsEventData> message) {
		try {
			service.send(message.getData());
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
	}

}
